package org.jivesoftware.smackx.workgroup.ext.macros;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class MacroGroup
{
  private List<MacroGroup> macroGroups;
  private List<Macro> macros = new ArrayList();
  private String title;

  public MacroGroup()
  {
    this.macroGroups = new ArrayList();
  }

  public void addMacro(Macro paramMacro)
  {
    this.macros.add(paramMacro);
  }

  public void addMacroGroup(MacroGroup paramMacroGroup)
  {
    this.macroGroups.add(paramMacroGroup);
  }

  public Macro getMacro(int paramInt)
  {
    return ((Macro)this.macros.get(paramInt));
  }

  public Macro getMacroByTitle(String paramString)
  {
    Object localObject;
    Iterator localIterator = Collections.unmodifiableList(this.macros).iterator();
    if (!(localIterator.hasNext()))
      localObject = null;
    while (true)
    {
      Macro localMacro;
      do
      {
        return localObject;
        localMacro = (Macro)localIterator.next();
      }
      while (!(localMacro.getTitle().equalsIgnoreCase(paramString)));
      localObject = localMacro;
    }
  }

  public MacroGroup getMacroGroup(int paramInt)
  {
    return ((MacroGroup)this.macroGroups.get(paramInt));
  }

  public MacroGroup getMacroGroupByTitle(String paramString)
  {
    Object localObject;
    Iterator localIterator = Collections.unmodifiableList(this.macroGroups).iterator();
    if (!(localIterator.hasNext()))
      localObject = null;
    while (true)
    {
      MacroGroup localMacroGroup;
      do
      {
        return localObject;
        localMacroGroup = (MacroGroup)localIterator.next();
      }
      while (!(localMacroGroup.getTitle().equalsIgnoreCase(paramString)));
      localObject = localMacroGroup;
    }
  }

  public List<MacroGroup> getMacroGroups()
  {
    return this.macroGroups;
  }

  public List<Macro> getMacros()
  {
    return this.macros;
  }

  public String getTitle()
  {
    return this.title;
  }

  public void removeMacro(Macro paramMacro)
  {
    this.macros.remove(paramMacro);
  }

  public void removeMacroGroup(MacroGroup paramMacroGroup)
  {
    this.macroGroups.remove(paramMacroGroup);
  }

  public void setMacroGroups(List<MacroGroup> paramList)
  {
    this.macroGroups = paramList;
  }

  public void setMacros(List<Macro> paramList)
  {
    this.macros = paramList;
  }

  public void setTitle(String paramString)
  {
    this.title = paramString;
  }

  public String toXML()
  {
    Iterator localIterator2;
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<macrogroup>");
    localStringBuilder.append("<title>" + getTitle() + "</title>");
    localStringBuilder.append("<macros>");
    Iterator localIterator1 = getMacros().iterator();
    if (!(localIterator1.hasNext()))
    {
      localStringBuilder.append("</macros>");
      if (getMacroGroups().size() > 0)
      {
        localStringBuilder.append("<macroGroups>");
        localIterator2 = getMacroGroups().iterator();
      }
    }
    while (true)
    {
      while (!(localIterator2.hasNext()))
      {
        localStringBuilder.append("</macroGroups>");
        localStringBuilder.append("</macrogroup>");
        return localStringBuilder.toString();
        Macro localMacro = (Macro)localIterator1.next();
        localStringBuilder.append("<macro>");
        localStringBuilder.append("<title>" + localMacro.getTitle() + "</title>");
        localStringBuilder.append("<type>" + localMacro.getType() + "</type>");
        localStringBuilder.append("<description>" + localMacro.getDescription() + "</description>");
        localStringBuilder.append("<response>" + localMacro.getResponse() + "</response>");
        localStringBuilder.append("</macro>");
      }
      localStringBuilder.append(((MacroGroup)localIterator2.next()).toXML());
    }
  }
}